<template>
  <div>
    <div class="pltxt" v-if="setName!=undefined">{{setName}}</div>
      <van-field
        v-model="setValue_parent"
        clickable
        readonly
        @click="showPicker = true"
      >
      <template #button>
        <van-button size="small" round @click="setOVEnable($event)" class="setbtn">{{$t('Save')}}</van-button>
      </template>
      </van-field>
      <van-popup v-model="showPicker" round position="bottom">
            <van-picker
              show-toolbar
              :columns="columns"
              @cancel="showPicker = false"
              @confirm="onConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')"
            />
      </van-popup>
  </div>
</template>

<script>

export default {
  props:['setName','columns','setValue','subOption'],
  data(){
    return {
      showPicker:false,
      code:this.setValue,
      setValue_parent:'',
    }
  },
  watch:{
    setValue(newVal){
      this.setValue_parent=this.columns[newVal];
      this.code=newVal;
    }
  },
  methods: {
    onConfirm(value,i){
      this.setValue_parent=value;
      this.showPicker=false;
      this.code=i;
    },
    async setOVEnable(e){
      e.stopPropagation();
      //处理数据
      let params={};
      params['optType']='newParaSetting';
      params['subOption']=this.subOption;
      params['sn']=localStorage.getItem('wifiSN');
      params['tokenId']=localStorage.getItem('tokenId');
      params['Value']=this.code;
      this.comm.loadingShow();
      let data = await this.SETAPI.setInvMachine(localStorage.getItem('domain'), params);
      if (data.success) {
        this.comm.toastSuccess();
        this.$emit('getFormData',this.code);
      } else {
        this.comm.toastFail();
      }
    }
  },
  mounted(){
    this.setValue_parent=this.columns[this.setValue];
    this.code=this.setValue;
  }
}
</script>

<style scoped lang="less">

</style>